let obj = {

  createPoster() {
    return new Promise((resolve, reject) => {
      uni.showLoading({
        title: '海报生成中'
      });
      const ctx = uni.createCanvasContext('poster');
      ctx.fillRect(0, 0, 375, 673);
      ctx.setFillStyle("#fff");
      ctx.fillRect(0, 0, 375, 673);
      uni.downloadFile({
        url: this.generate.image,
        success: (res) => {
          if (res.statusCode === 200) {
            let textTop = 0;
            let w = this.clientWidth
            uni.getScreenInfoSync()
            ctx.drawImage(res.tempFilePath, 10, 10, 355, 355);
            uni.downloadFile({
              url: this.generate.qrcode,
              success: (res2) => {
                if (res.statusCode === 200) {
                  // 商品标题
                  ctx.setFontSize(21);
                  ctx.setFillStyle('#333');
                  let drawtextList = drawtext(this.generate.name, 341);
                  drawtextList.forEach((item, index) => {
                    if (index < 2) {
                      textTop = 380 + (index + 1) * 28;
                      ctx.fillText(item.content, 17, textTop);
                    }
                  });

                  ctx.beginPath();
                  ctx.setLineWidth(1);
                  ctx.moveTo(17, textTop + 60);
                  ctx.lineTo(358, textTop + 60);
                  ctx.setStrokeStyle('#eee');
                  ctx.stroke();
                  // 长按识别二维码访问
                  ctx.setFontSize(19);
                  ctx.setFillStyle('#333');
                  ctx.fillText('点击微信打开扫一扫', 17, textTop + 136);
                  this.drawCircular(ctx, w * 0.2, w * 0.2, (w - w * 0.2) / 2, w * 0.1, this.generate.headimgurl)
                  // 平台名称
                  ctx.setFontSize(16);
                  ctx.setFillStyle('#999');
                  ctx.fillText("微信识别小程序码", 17, textTop + 170);
                  // 二维码
                  ctx.drawImage(res2.tempFilePath, 238, textTop + 88, 120, 120);
                  ctx.draw(true, () => {
                    // canvas画布转成图片并返回图片地址
                    uni.canvasToTempFilePath({
                      canvasId: 'poster',
                      width: 375,
                      height: 673,
                      success: (res) => {
                        if (this.posterImgs[this.swiperIndex]) {
                          this.posterImgs[this.swiperIndex].temporary = res.tempFilePath;
                        } else {
                          this.posterImgs[this.swiperIndex] = {
                            temporary: res.tempFilePath
                          };
                        }
                        console.log("海报制作成功！");
                        resolve(res.tempFilePath);
                      },
                      fail: () => {
                        uni.hideLoading();
                        reject();
                      }
                    })
                  });
                } else {
                  uni.hideLoading();
                  uni.showToast({
                    title: '海报制作失败，图片下载失败',
                    icon: 'none'
                  });
                }
              },
              fail: err => {
                uni.hideLoading();
                uni.showToast({
                  title: '海报制作失败，图片下载失败',
                  icon: 'none'
                });
              }
            });
          } else {
            uni.hideLoading();
            uni.showToast({
              title: '海报制作失败，图片下载失败',
              icon: 'none'
            });
          }
        },
        fail: err => {
          uni.hideLoading();
          uni.showToast({
            title: '海报制作失败，图片下载失败',
            icon: 'none'
          });
        }
      });
    });
  },



  save: function () {

    if (settingWritePhotosAlbum) {

      uni.getSetting({
        success: res => {
          if (res.authSetting['scope.writePhotosAlbum']) {
            uni.saveImageToPhotosAlbum({
              filePath: imgUrl,
              success: () => {
                uni.hideLoading();
                uni.showToast({
                  title: '保存成功'
                });
              }
            });
          } else {
            uni.showModal({
              title: '提示',
              content: '请先在设置页面打开“保存相册”使用权限',
              confirmText: '去设置',
              cancelText: '算了',
              success: data => {
                if (data.confirm) {
                  uni.hideLoading();
                  uni.openSetting();
                }
              }
            });
          }
        }
      });



    } else {
      settingWritePhotosAlbum = true;
      uni.authorize({
        scope: 'scope.writePhotosAlbum',
        success: () => {

        }
      });
    }


    uni.saveImageToPhotosAlbum({
      filePath: imgUrl,
      success: () => {
        uni.hideLoading();
      }
    });
  }



  // #endif
},

  

}

function save() {
  drawCircular(ctx, url, x, y, width, height) {
    //画圆形头像
    ctx.save();
    ctx.beginPath();
    ctx.arc(width / 2 + x, height / 2 + y, width / 2, 0, Math.PI * 2, false);
    ctx.clip();
    ctx.drawImage(url, x, y, width, height);
    ctx.restore();
  }
  fillRoundRect(cxt, x, y, width, height, radius, /*optional*/ fillColor) {
    //圆的直径必然要小于矩形的宽高
    if (2 * radius > width || 2 * radius > height) {
      return false;
    }

    cxt.save();
    cxt.translate(x, y);
    //绘制圆角矩形的各个边
    _this.drawRoundRectPath(cxt, width, height, radius);
    cxt.fillStyle = fillColor || '#000'; //若是给定了值就用给定的值否则给予默认值
    cxt.fill();
    cxt.restore();
  }
  drawRoundRectPath(cxt, width, height, radius) {
    cxt.beginPath(0);
    //从右下角顺时针绘制，弧度从0到1/2PI
    cxt.arc(width - radius, height - radius, radius, 0, Math.PI / 2);

    //矩形下边线
    cxt.lineTo(radius, height);

    //左下角圆弧，弧度从1/2PI到PI
    cxt.arc(radius, height - radius, radius, Math.PI / 2, Math.PI);

    //矩形左边线
    cxt.lineTo(0, radius);

    //左上角圆弧，弧度从PI到3/2PI
    cxt.arc(radius, radius, radius, Math.PI, (Math.PI * 3) / 2);

    //上边线
    cxt.lineTo(width - radius, 0);

    //右上角圆弧
    cxt.arc(width - radius, radius, radius, (Math.PI * 3) / 2, Math.PI * 2);

    //右边线
    cxt.lineTo(width, height - radius);
    cxt.closePath();
  }
}